public class DynamicArrayExample {
    public static void main(String[] args) {
        // 初始化一个大小为5的整数数组
        int[] oldArray = new int[5];
        for (int i = 0; i < oldArray.length; i++) {
            oldArray[i] = i + 1;
        }

        // 打印旧数组
        System.out.println("Old array:");
        for (int i : oldArray) {
            System.out.print(i + " ");
        }
        System.out.println();

        // 动态调整数组大小为8
        int[] newArray = new int[8];
        for (int i = 0; i < oldArray.length; i++) {
            newArray[i] = oldArray[i];
        }

        // 打印新数组
        System.out.println("New array:");
        for (int i : newArray) {
            System.out.print(i + " ");
        }
    }
}